<!--
 * @Author: yuqy
 * @Date: 2023-10-23 15:56:24
 * @LastEditors: yuqy
 * @LastEditTime: 2023-10-23 17:24:41
 * @Descripttion: -
-->
<template>
  <div class="container">
    <div class="bindBox">
      <div class="itemBox frow">
        <div class="frow">
          <img src="@/assets/img/login/weixin.png" alt class="bindImg">
        </div>
        <div class="fcol faic btnBox">
          <p class="bindLabel" @click="bind('wx')" v-ripple>
            {{ wechatBind ? "已绑定" : "未绑定" }}
            <Icon v-if="!wechatBind" size="24" type="ios-arrow-forward"/>
          </p>
          <div :class="wechatBind ? 'bindClass cp' : 'notBindClass'" @click="unbindWx">解除绑定</div>
        </div>
      </div>

      <div class="itemBox frow">
        <div class="frow">
          <img src="@/assets/img/login//钉钉.png" alt class="bindImg">
        </div>
        <div class="fcol faic btnBox">
          <p class="bindLabel" @click="bind('dd')" v-ripple>
            {{ dingTalkBind ? "已绑定" : "未绑定" }}
            <Icon v-if="!dingTalkBind" size="24" type="ios-arrow-forward"/>
          </p>
          <div :class="dingTalkBind ? 'bindClass cp' : 'notBindClass '" @click="unbindDd">解除绑定</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { Icon, Message } from "view-ui-plus";
import { mapActions, mapState } from "vuex";
import {
  deleteWechatUnbind,
  deleteDingtalkUnbind
} from "@/api/user";
export default {
  data() {
    return {};
  },
  mounted() {},
  components: {
    Icon
  },
  computed: {
    ...mapState({
      userInfo: state => state.user.userInfo
    }),
    dingTalkBind() {
      return this.userInfo.dingtalkUser && this.userInfo.dingtalkUser.nick;
    },
    wechatBind() {
      return this.userInfo.wechatUser && this.userInfo.wechatUser.nick;
    }
  },
  methods: {
    ...mapActions("user", ["getUserInfo"]),
    bind(type) {
      if (type == "wx") {
        if (this.wechatBind) {
          return Message.error("您已绑定微信");
        }
      }
      if (type == "dd") {
        if (this.dingTalkBind) {
          return Message.error("您已绑定钉钉");
        }
      }
    },
    async unbindWx() {
      if (!this.wechatBind) {
        return Message.error("您还未绑定微信");
      }
      await deleteWechatUnbind();
      await this.getUserInfo();
    },
    async unbindDd() {
      if (!this.dingTalkBind) {
        return Message.error("您还未绑定钉钉");
      }
      await deleteDingtalkUnbind();
      await this.getUserInfo();
    }
  }
};
</script>

<style lang="less" scoped>
.container {
  padding-left: 0px;
  .bindBox {
    .itemBox {
      padding: 12px 12px 12px 0;
      margin-bottom: 0px;
      border-bottom: 1px solid rgba(124, 124, 124, 0.2);
      justify-content: space-between;
      align-items: center;
      .bindImg {
        width: 56px;
        min-width: 56px;
        height: 56px;
        margin-left: 32px;
      }
      .bindLabel {
        font-size: 16px;
        color: @mainColor;
        margin-bottom: 0px;
        padding: 4px 20px;
      }
      .btnBox {
        user-select: none;
        .bindClass {
          padding: 7px 14px;
          background: @mainColor;
          color: #ffffff;
          border-radius: 8px;
          font-size: 14px;
          font-weight: 400;
        }
        .notBindClass {
          padding: 7px 0px;
          font-size: 14px;
          font-weight: 400;
          color: #c6c8c5;
          cursor: no-drop;
        }
      }
    }
  }
}
</style>
